<template>
  <div class="common-layout">
    <el-container>
      <el-header height="60px" class="header">
        <div class="header-content">
          <h2>会议室预订系统</h2>
          <div class="header-actions">
            <el-button type="primary" @click="handleLogout">退出登录</el-button>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px" class="aside">
          <el-menu :default-active="activeTab" class="side-menu" @select="navigateToTab">
            <el-menu-item index="meetingRooms">
              <span>会议室</span>
            </el-menu-item>
            <el-menu-item index="bookRoom">
              <span>预订会议室</span>
            </el-menu-item>
            <el-menu-item index="myReservations">
              <span>我的订单</span>
            </el-menu-item>
            <el-menu-item index="profile">
              <span>个人信息</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main class="main-content">
          <div class="dashboard-content">
            <el-tabs v-model="activeTab" class="dashboard-tabs">
              <el-tab-pane label="会议室" name="meetingRooms">
                <MeetingRoomsView />
              </el-tab-pane>
              <el-tab-pane label="预订会议室" name="bookRoom">
                <BookRoomView />
              </el-tab-pane>
              <el-tab-pane label="我的订单" name="myReservations">
                <CancellationRequestView />
              </el-tab-pane>
              <el-tab-pane label="个人信息" name="profile">
                <ProfileView />
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { ElPageHeader, ElButton, ElTabs, ElTabPane } from 'element-plus'
import { useAuthStore } from '@/stores/auth'
import BookRoomView from './BookRoomView.vue'
import CancellationRequestView from './CancellationRequestView.vue'
import MeetingRoomsView from './MeetingRoomsView.vue'
import ProfileView from './ProfileView.vue'

export default {
  name: 'CustomerDashboardView',
  components: {
    ElPageHeader,
    ElButton,
    ElTabs,
    ElTabPane,
    BookRoomView,
    CancellationRequestView,
    MeetingRoomsView,
    ProfileView,
  },
  setup() {
    const authStore = useAuthStore()
    return { authStore }
  },
  data() {
    return {
      activeTab: this.$route.query.tab || 'meetingRooms', // 默认显示会议室页面
      // Removed static reservations data as CancellationRequestView will handle its own
    }
  },
  watch: {
    '$route.query.tab'(newTab) {
      if (newTab) {
        this.activeTab = newTab
      }
    },
  },
  methods: {
    navigateToTab(tab) {
      this.activeTab = tab
      this.$router.replace({
        query: { ...this.$route.query, tab },
      })
    },

    goBack() {
      this.$router.go(-1)
    },
    handleLogout() {
      this.authStore.logout()
    },
  },
}
</script>

<style scoped>
.header {
  background-color: #409eff;
  color: white;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
}

.aside {
  background-color: white;
  border-right: 1px solid #e6e6e6;
}

.side-menu {
  border-right: none;
}

.main-content {
  padding: 0;
  background-color: #f5f7fa;
}

.dashboard-content {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.dashboard-tabs {
  :deep(.el-tabs__header) {
    background-color: white;
    border-radius: 8px;
    padding: 0 24px;
    margin: 0;
  }
  :deep(.el-tabs__nav-wrap) {
    padding: 0 8px;
  }
  :deep(.el-tabs__item) {
    padding: 0 16px;
    height: 48px;
    line-height: 48px;
    color: #606266;
    font-weight: 500;
    &.is-active {
      color: #409eff;
    }
    &:hover {
      color: #409eff;
    }
  }
  :deep(.el-tabs__active-bar) {
    background-color: #409eff;
  }
  :deep(.el-tabs__content) {
    background-color: white;
    border-radius: 8px;
    margin-top: 16px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  }
}
</style>
